<?php

namespace App\Models;

use Dcat\Admin\Models\Administrator;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'email',
        'gender',
        'address',
        'status',
        'mobile',
        'create_admin_id',
        'update_admin_id',
        'type'
    ];

    const GENDER_MAN = 0;
    const GENDER_WOMAN = 1;

    public static $genderMap = [
        self::GENDER_MAN => '男',
        self::GENDER_WOMAN => '女'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'address' => 'json',
    ];

    const TYPE_DEFAULT = 0;
    const TYPE_LANDLORD = 1;

    public static $typeMap = [
        self::TYPE_DEFAULT => '默认用户',
        self::TYPE_LANDLORD => '收款人'
    ];

    public function owner()
    {
        return $this->hasMany(Owner::class);
    }

    public function createAdmin()
    {
        return $this->belongsTo(Administrator::class, 'create_admin_id');
    }

    public function updateAdmin()
    {
        return $this->belongsTo(Administrator::class, 'update_admin_id');
    }
}
